<%@page import="com.grom.util.Constants"%>
<%@page import="com.grom.service.CustomerService"%>
<%@page import="com.grom.po.Customer"%>
<%@page import="com.grom.util.SecurityUtil"%>
<%@page import="com.grom.po.GcmsUser"%>
<%@page import="com.grom.po.StoreInfo"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script>

<script type="text/javascript">
<%
if(session.getAttribute("USER")!=null&&session.getAttribute("USER").equals("ADMIN")){
	%>
	currentUserId="ADMIN";
	<%
}
if(session.getAttribute("USER")!=null&&session.getAttribute(Constants.KEY_USER_SESSION)!=null){
	%>
	currentUserId="<%=((GcmsUser)session.getAttribute(Constants.KEY_USER_SESSION)).getID() %>";
	<%
}
%>
$(function(){
	$('#loginInfoEdit').dialog({  
	    title : '店铺信息 录入',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit').dialog('close');
});


function showAddDialog(){
	$('input').each(function(){
		$(this).val('');
	});
	$('select').each(function(){
		$(this).val('');
	});
	$('#loginInfoEdit').dialog('open');
}

function loginInfoEdit(){
	$('#loginInfoEdit').dialog('close');
}
function viewDetail(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	$.ajax({
	    url: '<%=request.getContextPath()%>/StoreInfoAction/getDetail.do?itemid='+itemId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var storeInfo = eval(json);
	        $('#ID').val(storeInfo.ID);
	        $('#shopOverviewId').val(storeInfo.shopOverviewId);
	        $('#codeOfABDStore').val(storeInfo.codeOfABDStore);
	        $('#storeAddress').val(storeInfo.storeAddress);
	        $('#businessArea').val(storeInfo.businessArea);
	        $('#numOfChunnel').val(storeInfo.numOfChunnel);
	        $('#businessStartTIme').val(storeInfo.businessStartTIme);
	        $('#businessEndTime').val(storeInfo.businessEndTime);
	        $('#dayOfVacation').val(storeInfo.dayOfVacation);
	        $('#numOfEmployee').val(storeInfo.numOfEmployee);
	        $('#userId').val(storeInfo.userId);
	        $('#customerId').val(storeInfo.customerId);
	        if(currentUserId == "ADMIN"||storeInfo.userId == currentUserId ||storeInfo.userId==""){
	        	$('#save').linkbutton('enable');
	        }else{
	        	$('#save').linkbutton('disable');
	        }
			$('#loginInfoEdit').dialog('open');
	    }
	});
}

function doDelete(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	if (itemId){  
        $.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){  
            if (r){  
				$('#deleteId').val(itemId);
				$('#deleteForm').submit();
            }  
        });  
    } 
}
function doSearch(){
	$('#searchForm').submit();
}
</script>
</head>
<body>
<div style="display: none;">
	<form name="deleteForm" id="deleteForm" action="<%=request.getContextPath() %>/StoreInfoAction/doDelete.do">
		<input type="text" name="deleteId" id="deleteId"/>
	</form>
</div>
<div style="font-size: 10px;">
	<form id="searchForm" name="searchForm" action="<%=request.getContextPath() %>/StoreInfoAction/conditionSelect.do" method="post">
      <label>shopOverviewId：</label>  
      <input type="text" name="shopOverviewId_s" id="shopOverviewId_s" ></input>  
      <label>ABD店代码：</label>  
      <input type="text" name="codeOfABDStore_s" id="codeOfABDStore_s" ></input>  
      <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">search</a>
    </form>
</div>
<table id="tt" class="easyui-datagrid"   
        title="店铺信息操作" iconCls="icon-save"  singleSelect="true"
        toolbar="#tb">  
    <thead>  
        <tr>  
            <th field="itemid" width="80">Item ID</th>  
            <th field="shopOverviewId" width="80">shop_overview_id</th>  
            <th field="codeOfABDStore" width="80" align="right">ABD店代码</th>  
            <th field="storeAddress" width="80" align="right">店所在物理位置</th>  
            <th field="businessArea" width="150">营业面积</th>  
            <th field="numOfEmployee" width="60" align="center">员工人数</th>  
        </tr>  
    </thead>  
    <tbody>     
    	<%
    		List<StoreInfo> allStoreInfos = (List<StoreInfo>)request.getAttribute("allStoreInfos");
    		for(StoreInfo storeinfo : allStoreInfos){
    	%>
        <tr>                             
            <td><%=storeinfo.getID() %></td>              
            <td><%=storeinfo.getShopOverviewId() %></td>              
            <td><%=storeinfo.getCodeOfABDStore() %></td>              
            <td><%=storeinfo.getStoreAddress() %></td>              
            <td><%=storeinfo.getBusinessArea() %></td>              
            <td><%=storeinfo.getNumOfEmployee() %></td>              
        </tr>  
    	<%
    		}
    	%>                         
    </tbody>
</table>  
<div id="tb">
<%
	if(session.getAttribute("USER")!=null){
%>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showAddDialog()">Add</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" onclick="viewDetail()">view/update</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="doDelete()">Delete</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">pre page</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">next page</a> 
<%
	}
%> 
</div>


<!-- 编辑 -->  
<div id="loginInfoEdit"  
    style="padding: 5px; width: 500px; height: 300px;">  
    <h5 id="loginInfoEdit_message" style="color: red;"></h5>  
    <div class="ToolTip_Form" id="table_loginInfoEdit" onkeydown="if(event.keyCode==13){loginInfoEdit();}">  
       <form id="storeInfoForm" name="storeInfoForm" action="<%=request.getContextPath() %>/StoreInfoAction/doSave.do" method="post">
       <input type="hidden"" name="ID" id="ID" value=""/>
       <ul>    
            <li>  
                <label>shop_overview_id：</label>  
                <input type="text" class="easyui-validatebox" name="shopOverviewId" id="shopOverviewId" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>ABD店代码：</label>  
                <input type="text" class="easyui-validatebox" name="codeOfABDStore" id="codeOfABDStore" maxlength_d="20" required="true"></input>  
            </li> 
            <li>  
                <label>店所在物理位置：</label>  
                <input type="text" class="easyui-validatebox" name="storeAddress" id="storeAddress" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>营业面积：</label>  
                <input type="text" class="easyui-validatebox" name="businessArea" id="businessArea" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>通道数目：</label>  
                <input type="text" class="easyui-validatebox" name="numOfChunnel" id="numOfChunnel" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>开门营业时间：</label>  
                <input type="text" class="easyui-validatebox" name="businessStartTIme" id="businessStartTIme" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>关门打烊时间：</label>  
                <input type="text" class="easyui-validatebox" name="businessEndTime" id="businessEndTime" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>节假日天数：</label>  
                <input type="text" class="easyui-validatebox" name="dayOfVacation" id="dayOfVacation" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>员工人数：</label>  
                <input type="text" class="easyui-validatebox" name="numOfEmployee" id="numOfEmployee" maxlength_d="20" required_d="true"></input>  
            </li> 
                        <li>  
                <label>销售人员：</label>  
                <select id="userId" name="userId" class="easyui-validatebox" required="true">
                	<option value="">无</option>
                	<%
                		List<GcmsUser> users = SecurityUtil.getAllUser();
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
            <li>  
                <label>客户信息：</label>  
                <select id="customerId" name="customerId" class="easyui-validatebox" required="true">
                	<option value="">无</option>
                	<%
                		List<Customer> customers = CustomerService.instance.getAllCustomer();
                		for(Customer cus : customers){
                			%>
                			<option value="<%=cus.getID() %>"><%=cus.getCustomerName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
            <li>  
            	<a href="#" class="easyui-linkbutton" onclick="$('#storeInfoForm').submit();">保存</a>
            	<a href="#" class="easyui-linkbutton" onclick="$('#loginInfoEdit').dialog('close');">放弃操作</a>
            </li>  
        </ul>  
       </form>
    </div>  
</div>  
</body>
</html>